class CxURLManager(object):
    def __init__(self):
        # 保存未爬的url的集合
        self.new_urls = []
        # 保存已爬的url的集合
        self.old_urls = []

    def Cx_has_new_url(self):
        # 通过地址列表的长度判断是否还有待爬取的新url地址
        return len(self.new_urls) != 0

    def Cx_get_new_url(self):
        # 从待爬url地址列表取出一个地址
        temp_url = self.new_urls[0]
        del (self.new_urls[0])
        # 然后将这个url地址放入到已爬队列中
        self.old_urls.append(temp_url)
        return temp_url

    def Cx_add_new_url(self, url):
        # 判断url地址是否为空;如果不空,将此地址加入到保存待爬取URL地址的集合
        try:
            if (url is None):
                print("url地址为空！！！！！！！！----------------------------------------")
                return
            if (url not in self.new_urls and url not in self.old_urls):
                self.new_urls.append(url)
        except:
            print("添加url地址错误！！！！！------------------------------------------")
            return

    def Cx_add_new_urls(self, urls):
        # 循环调用add-new_url,将urls中的地址加入保存待爬取URL地址的集合:直至urls为空。
        if (urls == None or len(urls) == 0):
            print("URLS列表为空！！！----------------------------------------------")
            return
        for url in urls:
            self.Cx_add_new_url(url)

    def Cx_new_url_size(self):
        # 返回集合new_urls的元素个数
        return len(self.new_urls)

    def Cx_old_url_size(self):
        # 返回集合old urls的元素个数
        return len(self.old_urls)
